public class MyQueue {
    public static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val){
            this.val=val;
        }
    }
    public ListNode head;
    public  ListNode last;
    public void offer(int data){
        ListNode node=new ListNode(data);
        if (head==null){
            head=node;
            last=node;
        }else {
            last.next=node;
            node.prev=last;
            last=node;
        }
    }
    public void poll(){
        if (head==null){
           throw new NullException("链表为空，没有元素可以进行删除");
        }
        if (head==last){
            head=null;
            last=null;
        }
       else {
           head= head.next;
           head.prev=null;
        }
    }
    public int peek(){
        if (head==null){
            throw new NullException("链表为空，没有元素可以进行删除");
        }
       return head.val;
    }
    public int size(){
        ListNode cur=this.head;
        int count=0;
        while (cur!=null){
            count++;
            cur=cur.next;
        }
        return count;
    }
    public boolean isEmpty(){
       if (head==null){
           return true;
       }
       return false;
    }
}
